﻿namespace DB2WORD.Models
{
    public class Project
    {
        internal bool IsModified = false;
        internal bool IsDetailsModified = false;
        public string ID { get; set; }
        public string Name { get; set; }
        public DBSetting DBSetting { get; set; } = new DBSetting();
        public DateTime CreateTime { get; set; }
        public DateTime? LastUpdateTime { get; set; }
        //public int Version { get; set; }
        public Version Version { get; set; }
        internal string ChangeLog { get; set; }
        public List<string>? TableNames { get; set; }
        public string Regexes { get; set; }
        public override string ToString()
        {
            return $"{this.Name} - V{this.Version}";
        }
    }
    public class DBSetting
    {
        public string? DbName { get; set; }
        public string? Server { get; set; }
        public string? User { get; set; }
        public string? Password { get; set; }
        public override string ToString()
        {
            return $"{this.Server} - {this.DbName}";
        }
    }

    public class TableInfo
    {
        public string TableID { get; set; }
        public string Name { get; set; }
        public string Label { get; set; }
        public string Description { get; set; }
        public List<ColumnInfo> Columns { get; set; }
        public List<IndexInfo> Indexes { get; set; }
        public override string ToString()
        {
            return $"{this.Label} - {this.Name}";
        }
    }

    public class GroupInfo
    {
        public string Name { get; set; }
        public List<TableInfo> Tables { get; set; }
        public override string ToString()
        {
            return $"{this.Name}";
        }
    }

    public class ColumnInfo
    {
        public string TableID { get; set; }
        public string Name { get; set; }
        public string Label { get; set; }
        public string Description { get; set; }
        public string Type { get; set; }
        public bool CanBeNull { get; set; }
        public string Default { get; set; }
        public bool IsIdentity { get; set; }
        public bool IsPrimary { get; set; }
        public int Sort { get; set; }
        public override string ToString()
        {
            return $"{this.Label} - {this.Name} - {this.Type}";
        }
    }
    public class IndexInfo
    {
        public string TableID { get; set; }
        public string Name { get; set; }
        public string Columns { get; set; }
        public string Description { get; set; }
        public int Sort { get; set; }
        public override string ToString()
        {
            return $"{this.Name}";
        }
    }

    public class EditModel
    {
        public string TableName { get; set; }
        public string TableLabel { get; set; }
        public string FieldName { get; set; }
        public string CurrentLabel { get; set; }
        public string SuggestedLabel { get; set; }
    }

    public class ChangeLog
    {
        public Version Version { get; set; }
        public DateTime Date { get; set; }
        public string Description { get; set; }
    }

    public class Result
    {
        public bool IsSuccess { get; set; }
        public string? Message { get; set; }
        public object? Data { get; set; }
        public T? As<T>()
        {
            if(this.Data is T t)
            {
                return t;
            }
            return default;
        }

        public static Result OK(object? data = null)
        {
            return new Result { IsSuccess = true, Data = data };
        }
        public static Result Fail(string? message = null)
        {
            return new Result { IsSuccess = false, Message = message };
        }
    }
}
